<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="巷道名称" prop="tunnelName">
        <el-input
          v-model="queryParams.tunnelName"
          placeholder="请输入巷道名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['dispatch:tunnelInfo:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['dispatch:tunnelInfo:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['dispatch:tunnelInfo:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['dispatch:tunnelInfo:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="tunnelInfoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
<!--
      <el-table-column label="矿井名称" align="center" prop="mineName" />
-->
      <el-table-column label="巷道名称" align="center" prop="tunnelName" />
      <el-table-column label="队组名称" align="center" prop="teamName" />
      <el-table-column label="关联工作面" align="center" prop="workfaceName" />
      <el-table-column label="净断面积" align="center" prop="acreage" />
      <el-table-column label="设计长度" align="center" prop="designLength" />
      <el-table-column label="断面形状" align="center" prop="sectionShape" />
      <el-table-column label="巷道状态" align="center" prop="tunnelState">
      <template slot-scope="scope">
        <dict-tag :options="dict.type.dispatch_tunnel_status" :value="scope.row.tunnelState"/>
      </template>
      </el-table-column>
      <el-table-column label="岩石类型" align="center" prop="lithology" />
      <el-table-column label="开始日期" align="center" prop="beginDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.beginDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="巷道类型" align="center" prop="tunnelType" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['dispatch:tunnelInfo:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['dispatch:tunnelInfo:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改巷道信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="巷道名称" prop="tunnelName">
          <el-input v-model="form.tunnelName" placeholder="请输入巷道名称" />
        </el-form-item>
        <el-form-item label="掘开队" prop="teamId">
          <el-select v-model="form.teamId" placeholder="请选择掘开队" clearable>
            <el-option v-for="item in teamOptions" :key="item.drivingTeamId" :label="item.teamName" :value="item.drivingTeamId" ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="高度" prop="height">
          <el-input v-model="form.height" placeholder="请输入高度" />
        </el-form-item>
        <el-form-item label="宽度" prop="width">
          <el-input v-model="form.width" placeholder="请输入宽度" />
        </el-form-item>
        <el-form-item label="净断面积" prop="acreage">
          <el-input v-model="form.acreage" placeholder="请输入净断面积" />
        </el-form-item>
        <el-form-item label="设计长度" prop="designLength">
          <el-input v-model="form.designLength" placeholder="请输入设计长度" />
        </el-form-item>
        <el-form-item label="巷道类型" prop="tunnelType">
          <el-select v-model="form.tunnelType" placeholder="请选择巷道类型" clearable>
            <el-option label="开拓" value="开拓"></el-option>
            <el-option label="准备" value="准备"></el-option>
            <el-option label="回采" value="回采"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="断面形状" prop="sectionShape">
          <el-select v-model="form.sectionShape" placeholder="请选择断面形状" clearable>
            <el-option label="矩形" value="矩形"></el-option>
            <el-option label="半圆拱形" value="半圆拱形"></el-option>
            <el-option label="梯形" value="梯形"></el-option>
            <el-option label="半梯形" value="半梯形"></el-option>
            <el-option label="圆弧拱形" value="圆弧拱形"></el-option>
            <el-option label="三心拱形" value="三心拱形"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="巷道状态" prop="tunnelState">
          <el-select v-model="form.tunnelState" placeholder="请选择巷道状态" clearable>
            <el-option
              v-for="dict in dict.type.dispatch_tunnel_status"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="岩石类型" prop="lithology">
          <el-select v-model="form.lithology" placeholder="请选择岩石类型" clearable>
            <el-option label="全煤" value="全煤"></el-option>
            <el-option label="全岩" value="全岩"></el-option>
            <el-option label="半煤" value="半煤"></el-option>
            <el-option label="穿层" value="穿层"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="掘进方式" prop="drivingMethod">
          <el-select v-model="form.drivingMethod" placeholder="请选择掘进方式" clearable>
            <el-option label="综掘" value="综掘"></el-option>
            <el-option label="炮掘" value="炮掘"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="运矸方式" prop="gangueMethod">
          <el-select v-model="form.gangueMethod" placeholder="请选择运矸方式" clearable>
            <el-option label="矿车" value="矿车"></el-option>
            <el-option label="皮带" value="皮带"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="支护方式" prop="supportType">
          <el-select v-model="form.supportType" placeholder="请选择支护方式" clearable>
            <el-option label="拱形棚" value="拱形棚"></el-option>
            <el-option label="锚杆网" value="锚杆网"></el-option>
            <el-option label="锚网索" value="锚网索"></el-option>
            <el-option label="锚网喷" value="锚网喷"></el-option>
            <el-option label="梯形棚" value="梯形棚"></el-option>
            <el-option label="锚杆锚索钢带网喷" value="锚杆锚索钢带网喷"></el-option>
            <el-option label="浆" value="浆"></el-option>
            <el-option label="单体锚杆" value="单体锚杆"></el-option>
            <el-option label="锚网喷+注浆锚索+壁后注浆" value="锚网喷+注浆锚索+壁后注浆"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="巷道坡度" prop="dipAngle">
          <el-input v-model="form.dipAngle" placeholder="请输入巷道坡度" />
        </el-form-item>
        <el-form-item label="开始日期" prop="beginDate">
          <el-date-picker clearable
            v-model="form.beginDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择开始日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="结束日期" prop="endDate">
          <el-date-picker clearable
            v-model="form.endDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择结束日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="排序" prop="sort">
          <el-input v-model="form.sort" placeholder="请输入排序" />
        </el-form-item>
        <el-form-item label="关联工作面" prop="workfaceId">
          <el-select v-model="form.workfaceId" placeholder="请选择关联工作面" clearable>
            <el-option v-for="item in workfaceOptions" :key="item.workfaceId" :label="item.workFaceName" :value="item.workfaceId" ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="标高上限" prop="datumMarkMax">
          <el-input v-model="form.datumMarkMax" placeholder="请输入标高上限" />
        </el-form-item>
        <el-form-item label="标高下限" prop="datumMarkMin">
          <el-input v-model="form.datumMarkMin" placeholder="请输入标高下限" />
        </el-form-item>
        <el-form-item label="掘高" prop="drivingHeight">
          <el-input v-model="form.drivingHeight" placeholder="请输入掘高" />
        </el-form-item>
        <el-form-item label="掘宽" prop="drivingWidth">
          <el-input v-model="form.drivingWidth" placeholder="请输入掘宽" />
        </el-form-item>
        <el-form-item label="掘断面积" prop="drivingAcreage">
          <el-input v-model="form.drivingAcreage" placeholder="请输入掘断面积" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listTunnelInfo, getTunnelInfo, delTunnelInfo, addTunnelInfo, updateTunnelInfo } from "@/api/dispatch/tunnelInfo";
import { listWorkfaceInfo} from "@/api/dispatch/workfaceInfo";
import { listDrivingTeam } from "@/api/dispatch/drivingTeam";

export default {
  name: "TunnelInfo",
  dicts:['dispatch_tunnel_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      //掘开队选项
      teamOptions:[],
      //工作面选项
      workfaceOptions:[],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 巷道信息表格数据
      tunnelInfoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        tunnelName: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  mounted() {
    let query = {pageNum:1,pageSize: 1000}
    listWorkfaceInfo(query).then(response => {
      this.workfaceOptions = response.rows;
    });

    //获取开掘队选项
    listDrivingTeam(query).then(response => {
      this.teamOptions = response.rows;
    });
  },
  methods: {
    /** 查询巷道信息列表 */
    getList() {
      this.loading = true;
      listTunnelInfo(this.queryParams).then(response => {
        this.tunnelInfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        tunnelId: null,
        tunnelName: null,
        mineId: null,
        mineName: null,
        teamId: null,
        teamName: null,
        height: null,
        width: null,
        acreage: null,
        designLength: null,
        sectionShape: null,
        tunnelState: null,
        lithology: null,
        drivingMethod: null,
        gangueMethod: null,
        supportType: null,
        deptId: null,
        deptName: null,
        dipAngle: null,
        isDel: null,
        beginDate: null,
        endDate: null,
        sort: null,
        tunnelType: null,
        workfaceId: null,
        workfaceName: null,
        datumMarkMax: null,
        datumMarkMin: null,
        drivingHeight: null,
        drivingWidth: null,
        drivingAcreage: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.tunnelId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加巷道信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const tunnelId = row.tunnelId || this.ids
      getTunnelInfo(tunnelId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改巷道信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.tunnelId != null) {
            updateTunnelInfo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addTunnelInfo(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const tunnelIds = row.tunnelId || this.ids;
      this.$modal.confirm('是否确认删除巷道信息编号为"' + tunnelIds + '"的数据项？').then(function() {
        return delTunnelInfo(tunnelIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('dispatch/tunnelInfo/export', {
        ...this.queryParams
      }, `tunnelInfo_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
